package com.Xingcang_Dianxue.WhutBank.Controllers.Client;

import com.Xingcang_Dianxue.WhutBank.Models.Model;
import com.Xingcang_Dianxue.WhutBank.Views.ClientMenuOptions;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.net.URL;
import java.util.ResourceBundle;

public class ClientMenuController implements Initializable {

    @FXML
    private Button contact_me_btn;

    @FXML
    private Button dashboard_btn;

    @FXML
    private Button logout_btn;

    @FXML
    private Button profile_btn;

    @FXML
    private Button save_btn;

    @FXML
    private Button transactionsList_btn;

    @FXML
    private Button withdrawal_btn;
    @FXML
    private Text user_name;


    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        user_name.setText(Model.getInstance().getClient().getUserName());
        addListeners();
    }

    private void addListeners() {
        dashboard_btn.setOnAction(actionEvent -> onDashboard());
        save_btn.setOnAction(actionEvent -> onSave());
        withdrawal_btn.setOnAction(actionEvent -> onWithdrawal());
        transactionsList_btn.setOnAction(actionEvent -> onTransactionsList());
        profile_btn.setOnAction(actionEvent -> onProfile());
        logout_btn.setOnAction(actionEvent -> onLogout());
        contact_me_btn.setOnAction(actionEvent -> onContactMe());
    }


    private void onLogout() {
        // 获取stage
        Stage stage = (Stage) dashboard_btn.getScene().getWindow();
        // 关闭客户端窗口
        Model.getInstance().getViewFactory().closeScene(stage);
        // 重新打开登录窗口
        Model.getInstance().getViewFactory().showLoginWindow();
        // 将客户端登录成功标志设置为 False
        Model.getInstance().setClientLoginSuccessFlag(false);
    }

    private void onProfile() {
        Model.getInstance().getViewFactory().getClientSelectedMenuItem().set(ClientMenuOptions.PROFILE);
    }

    private void onTransactionsList() {
        Model.getInstance().getViewFactory().getClientSelectedMenuItem().set(ClientMenuOptions.TRANSACTIONSLIST);
    }

    private void onTransaction() {
        Model.getInstance().getViewFactory().getClientSelectedMenuItem().set(ClientMenuOptions.TRANSACTION);
    }

    private void onWithdrawal() {
        Model.getInstance().getViewFactory().getClientSelectedMenuItem().set(ClientMenuOptions.WITHDRAWAL);
    }

    private void onSave() {
        Model.getInstance().getViewFactory().getClientSelectedMenuItem().set(ClientMenuOptions.SAVE);
    }

    private void onDashboard() {
        Model.getInstance().getViewFactory().getClientSelectedMenuItem().set(ClientMenuOptions.DASHBOARD);
    }

    private void onContactMe() {
    }


}
